/*
 * Group 3, User Interface Programming II (vt11)
 * Pooya | Flora | Monica | Can
 */
package vical.utility;

import com.sun.awt.AWTUtilities;
import java.awt.Window;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import javax.swing.JFrame;

/**
 * The class to provide functions of changing transparency
 * 
 * @author Can
 * @author WoKe
 */
public class TransparencyManager {

    public static void setOpacity(float opaValue, JFrame window) {
        if (AWTUtilities.isTranslucencySupported(AWTUtilities.Translucency.TRANSLUCENT)) {
            try {
                //perform translucency operations here
                //            setWindowOpacity(this, 0.5f);
                Class<?> awtUtilitiesClass = Class.forName("com.sun.awt.AWTUtilities");
                Method mSetWindowOpacity = awtUtilitiesClass.getMethod("setWindowOpacity", Window.class, float.class);
                mSetWindowOpacity.invoke(null, window, Float.valueOf(opaValue));
            } catch (IllegalAccessException ex) {
                System.out.println(ex.getLocalizedMessage());
            } catch (IllegalArgumentException ex) {
                System.out.println(ex.getLocalizedMessage());
            } catch (InvocationTargetException ex) {
                System.out.println(ex.getLocalizedMessage());
            } catch (NoSuchMethodException ex) {
                System.out.println(ex.getLocalizedMessage());
            } catch (SecurityException ex) {
                System.out.println(ex.getLocalizedMessage());
            } catch (ClassNotFoundException ex) {
                System.out.println(ex.getLocalizedMessage());
            }
        }
    }
}
